package com.itheima.controller;

import com.itheima.common.R;
import com.itheima.entity.dto.order.OrderStatusDto;
import com.itheima.entity.vo.order.OrderPageVo;
import com.itheima.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author huangzelnag
 * @create 2022-05-12
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    OrderService orderService;


    /**
     * 分页条件查询订单
     * @param beginTime
     * @param endTime
     * @param number
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public R getOrderPage( @RequestParam(required = false) Integer page,
                           @RequestParam(required = false) Integer pageSize,
                           @RequestParam(required = false) String number,
                           @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")@RequestParam(required = false) Date beginTime,
                           @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")@RequestParam(required = false) Date endTime
                          ){
        OrderPageVo orderPageVo= orderService.getOrderPage(beginTime,endTime,number,page,pageSize);

        return R.success(orderPageVo);
    }


    /**
     * 修改订单状态
     * @param OrderStatusDto
     * @return
     */
    @PutMapping
    public R upOrderStatus(@RequestBody  OrderStatusDto OrderStatusDto){

       Boolean flag =   orderService.upOrderStatus(OrderStatusDto);
        if(flag){
            return R.success("修改成功");
        }

        return R.error("修改错误");
    }



}
